package com.yao.annotation;
 
import java.lang.reflect.Field;
 
/**
 * Created by Kangjun on 2015/11/22.
 */
public class FruitUtil {
 
    public static void getFruitInfo(Class<?> clazz){
        Field[] fields = clazz.getDeclaredFields();
        if (fields != null && fields.length > 0){
            for (Field field : fields) {
                if (field.isAnnotationPresent(FruitName.class)) {
                    FruitName fruitName = field.getAnnotation(FruitName.class);
                    System.out.println("水果名为："+fruitName.name());
                }else if (field.isAnnotationPresent(FruitColor.class)){
                    FruitColor fruitColor = field.getAnnotation(FruitColor.class);
                    System.out.println("水果的颜色为:" + fruitColor.color());
                }else if (field.isAnnotationPresent(FruitProvider.class)){
                    FruitProvider fruitProvider = field.getAnnotation(FruitProvider.class);
                    System.out.println("水果的提供id："+fruitProvider.id()+",名字为："+fruitProvider.name()+",价格为："+fruitProvider.price()+",产地为："+fruitProvider.address());
                }
            }
        }
 
    }
}